"""
    Cash register department name controller.
"""

from mnemoply import model
from mnemoply.controllers.lookup import LookupController, TableCol, SQLObjectLookupDataSource
from mnemoply.controllers.crud import CRUDController

class CashRegisterDepartmentNameDataSource(SQLObjectLookupDataSource):
    """
        Provides data source lookup for cash register departmant name table.
    """

    def __init__(self, model_object):
        SQLObjectLookupDataSource.__init__(self, model_object)

    def _buildQuery(self, request):
        query = SQLObjectLookupDataSource._buildQuery(self, request)
        return [n for n in query if n.id != 1]

    def getTotal(self, request):
        return len(self._buildQuery(request))

class CashRegisterDepartmentNameController(LookupController, CRUDController):
    model_object = model.CashRegisterDepartmentName
    lookup_columns = [
        TableCol(name='name', caption=_('Name')),
    ]
    view_fields = ['name']

    def __init__(self):
        LookupController.__init__(self,
            data_source=CashRegisterDepartmentNameDataSource(self.model_object),
            columns=self.lookup_columns,
            title=self.model_object.model_title,
        )
        CRUDController.__init__(self, model_object=self.model_object)

exposed = CashRegisterDepartmentNameController()
